package com.t174.car.controller;

import com.t174.car.dao.GuestsDao;
import com.t174.car.entity.Guests;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.annotation.RequestScope;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/guests")
@Scope("prototype")
public class GuestsController {
    @Autowired
    GuestsDao guestsDao;
    @RequestMapping("/query")
    @ResponseBody
    public List<Guests> setGuestsDao(){
        System.out.println("GuestsController.setGuestsDao");
       return guestsDao.query();
    }
    @RequestMapping("/save")
    @ResponseBody
    public int save(Guests guests){
        return guestsDao.getGuests(guests);
    }
//    @RequestMapping("/dele")
////    @ResponseBody
////    public  int dele(int id){
////        return  guestsDao.delGuests(id);
////    }
@RequestMapping("/deleteRoom")
@ResponseBody
public int del(String ids){
    String[] ss = ids.split("-");
    Integer[] myids = new Integer[ss.length] ;
    for(int i=0;i<ss.length;i++){
        System.out.println(ss[i]);
        myids[i] = Integer.parseInt(ss[i]) ;
    }
    return guestsDao.delGuests(myids);
}

    @RequestMapping("/getGuestsid")
    @ResponseBody
    public Guests getGuestsid(int id){
        return guestsDao.getGuestsid(id);
    }

    @RequestMapping("/upGuests")
    @ResponseBody
    public int updateGuests(Guests guests){
        return guestsDao.updateGuests(guests);
    }
 @RequestMapping("/shiws")
    @ResponseBody
    public  List<Guests> shiws(int id){
        return  guestsDao.showsGuests(id);
 }
}
